package com.chilly.other.atomic;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by Chilly Cui on 2020/12/30.
 */
public class AtomicIntegerTest {

    public static void main(String[] args) {

        int tempVal = 0;
        AtomicInteger i = new AtomicInteger(0);

        tempVal = i.getAndSet(3);
        System.out.println("tempVal:" + tempVal + ";  i:" + i);//tempVal:0;  i:3

        tempVal = i.getAndIncrement();
        System.out.println("tempVal:" + tempVal + ";  i:" + i);//tempVal:3;  i:4

        tempVal = i.getAndAdd(5);
        System.out.println("tempVal:" + tempVal + ";  i:" + i);//tempVal:4;  i:9

    }
}
